using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using Tycho.Lexer;
using Tycho.Parser.Peg;
using Tycho.Parser.Tokens;

namespace Tycho.Parser.Tests.Peg {
    [TestFixture]
    public class KeywordTerminalSpecification {
        [Test]
        public void ShouldReturnNonNullForCorrectIdentifierAndIncrementIndex () {
            var id = new KeywordTerminal<object> ("a");

            List<Token> tokens = NativeLexer.Lex ("a b c");

            ParseResult<object> result = id.Parse (tokens.ToArray (), 0, null);
            Assert.AreEqual (1, result.Index);
            Assert.IsNull (result.Term);
        }

        [Test]
        public void ShouldReturnNullForNonIdentifierTokenAndNotIncrementIndex () {
            var id = new KeywordTerminal<object> ("a");

            List<Token> tokens = NativeLexer.Lex ("8 b c");

            Assert.IsNull (id.Parse (tokens.ToArray (), 0, null));
        }

        [Test]
        public void ShouldReturnNullForIncorrectIdentifierTokenAndNotIncrementIndex () {
            var id = new KeywordTerminal<object> ("a");

            List<Token> tokens = NativeLexer.Lex ("x b c");

            Assert.IsNull (id.Parse (tokens.ToArray (), 0, null));
        }

        [Test]
        public void ShouldReturnNullIfIndexIsOutOfBounds () {
            var id = new KeywordTerminal<object> ("a");

            List<Token> tokens = NativeLexer.Lex ("a b c");

            Assert.IsNull (id.Parse (tokens.ToArray (), 3, null));
        }
    }
}